package cas;




import java.util.concurrent.atomic.AtomicInteger;

public class demo1 {

    private static AtomicInteger count = new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        System.out.println("++操作后："+count);
        Thread t1 = new Thread(()->{
            for(int i=0;i<50000;i++) {
                count.getAndIncrement();
            }
        });
        Thread t2 = new Thread(()->{
            for(int i=0;i<50000;i++) {
                count.getAndIncrement();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("++操作后："+count);

    }
    private static int count1 = 0;

    public static void main1(String[] args) throws InterruptedException {
        System.out.println("++操作前："+count1);
        Thread t1 = new Thread(()->{
            for(int i=0;i<50000;i++) {
                count1++;
            }
        });
        Thread t2 = new Thread(()->{
            for(int i=0;i<50000;i++) {
                count1++;
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("++操作后："+count1);
    }




}
